<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script src='https://cdn.staticfile.org/react/16.4.0/umd/react.development.js'></script>
    <script src='https://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js'></script>
    <!-- 生产环境中不建议使用 -->
    <script src='https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js'></script>
</head>

<body>
    <div id='app'>
    </div>
    <script type='text/babel'>
        class Weather  extends React.Component{
            constructor(props){
                super(props)
                this.state = {isHot:true}

                /*
                    解决的方式也很简单, 既然会有this指向的问题, 那不如把这个函数用bind定死this指向, 然后再给实例对象创建一个changeWeather属性, 把定死this指向的方法赋值给他就好了. 这样就永远都不会有this指向的问题了. 
                */
                this.changeWeather = this.changeWeather.bind(this)
            }

            
            changeWeather(){
                console.log(this)
            }

            render(){
                return <h1 onClick={this.changeWeather}>今天天气很{this.state.isHot?'炎热':'凉爽'}</h1>
            }
        }

        ReactDOM.render(<Weather/>,document.getElementById('app'))
    </script>
</body>

</html>